<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8">
<title>评价管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="../../static/lib/layui/css/layui.css" th:href="@{/lib/layui/css/layui.css}" media="all">
<script src="../../static/lib/layui/layui.js" th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script src="../../static/lib/jquery/jquery-3.2.1.min.js" th:src="@{/lib/jquery/jquery-3.2.1.min.js}"></script>
<script src="../../static/js/common/public.js" th:src="@{/js/common/public.js}"></script>
<style type="text/css">
    .form-padding {
        padding: 10px;
    }

</style>
</head>
<body>
<!--<form class="layui-form form-padding" id="search-form">
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <div class="layui-btn" id="submit">搜索</div>
        </div>
    </div>
</form>-->
<table id="list" lay-filter="data-table"></table>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="put-top">置顶</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel-put-top">取消置顶</a>
</script>
<script type="application/javascript" th:inline="none">
    (function () {
        let layer;
        layui.use('element', function () {
            var element = layui.element;
        });
        layui.use('form', function () {
            /*var form = layui.form;
            //监听提交
            form.on('submit(formDemo)', function (data) {
                layer.msg(JSON.stringify(data.field));
                return false;
            });*/
        });

        layui.use('layer', function () {
            layer = layui.layer;
        });

        function bindAction() {
            $('#submit').click(function () {
                render(constructArgs($('#search-form')))
            })
        }
        render({
            page:1
            ,limit:10
        })
        function render(param) {
            var table = null;
            layui.use('table', function () {
                table = layui.table;
                table.render({
                    elem: '#list'
                    , autoSort: true
                    //,width: 900
                    //,height: 274
                    , cols: [[
                        {field: 'evaluateId', title: '评价id', align: 'center'}
                        , {field: 'userId', title: '用户id', align: 'center'}
                        , {field: 'userName', title: '用户名', align: 'center'}
                        , {field: 'grade', title: '评分', align: 'center'}
                        , {field: 'content', title: '评价内容', align: 'center'}
                        , {field: 'likeNum', title: '点赞数', align: 'center'}
                        , {field: 'courseId', title: '课程id', align: 'center'}
                        , {field: 'isTop', title: '是否置顶', align: 'center'}
                        , {field: 'creatTime', title: '创建时间', align: 'center'}
                        , {fixed: 'right', title: '操作', toolbar: '#toolBar', align: 'center',width:200}
                    ]]
                    , url: '/interface/evaluate/getAll'
                    , response: {
                        statusName: 'status' //规定数据状态的字段名称，默认：code
                        , statusCode: 0 //规定成功的状态码，默认：0
                        , msgName: 'description' //规定状态信息的字段名称，默认：msg
                        , countName: 'count' //规定数据总数的字段名称，默认：count
                        , dataName: 'data' //规定数据列表的字段名称，默认：data
                    }
                    , where: param
                    , skin: 'row' //表格风格
                    , even: true
                    //,size: 'lg' //尺寸

                    , page: true //是否显示分页
                    //, limits: [3, 5, 10]
                    , loading: true //请求数据时，是否显示loading
                });
                table.on('edit(data-table)', function (obj) {
                    let value = obj.value //得到修改后的值
                        , data = obj.data //得到所在行所有键值
                        , field = obj.field; //得到字段
                    layer.confirm('确定更改?', function () {
                        var param = {
                            id: data.id
                        };
                        param[field] = value;
                    })

                })
                table.on('tool(data-table)', function (obj) {
                    let value = obj.value //得到修改后的值
                        , data = obj.data //得到所在行所有键值
                        , field = obj.field; //得到字段
                    if (obj.event === 'put-top') {
                        putTop({
                            evaluateId: data.evaluateId
                        })
                    } else if (obj.event === 'cancel-put-top') {
                        cancelPutTop({
                            evaluateId: data.evaluateId
                        })
                    }
                });
            });
        };

        function putTop(param) {
            $.ajax({
                url: '/interface/evaluate/top'
                , data: param
                , success: function (data) {
                    if (data) {
                        layer.msg("置顶成功")
                        location.reload();
                    }
                }
            })
        }

        function cancelPutTop(param) {
            $.ajax({
                url: '/interface/evaluate/unTop'
                , data: param
                , success: function (data) {
                    if (data) {
                        layer.msg("取消置顶成功")
                        location.reload();
                    }
                }
            })
        }

        bindAction();
    })()

</script>
</body>
</html>